From: Julian Sparber Date: Wed, 14 Feb 2024 14:45:50 +0000 (+0100) Subject: messageTray: Add action-added/action-removed signals to Notification X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~281^2~1^2~25 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=7ff5f4ea51f1d27b9fb5bc4440f1cc909d58f6d7;p=gnome-shell.git messageTray: Add action-added/action-removed signals to Notification Add signals so that the message actor can update the it's action when they change. Part-of: --- diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index d7d21f666..72db9579e 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -333,6 +333,24 @@ class Sound extends GObject.Object { } }); +export const Action = GObject.registerClass( +class Action extends GObject.Object { + constructor(label, callback) { + super(); + + this._label = label; + this._callback = callback; + } + + get label() { + return this._label; + } + + activate() { + this._callback(); + } +}); + // Notification: // @source: the notification's Source // @title: the title @@ -393,6 +411,8 @@ export const Notification = GObject.registerClass({ false), }, Signals: { + 'action-added': {param_types: [Action]}, + 'action-removed': {param_types: [Action]}, 'activated': {}, 'destroy': {param_types: [GObject.TYPE_UINT]}, 'updated': {param_types: [GObject.TYPE_BOOLEAN]}, @@ -453,7 +473,7 @@ export const Notification = GObject.registerClass({ this.gicon = params.gicon; if (params.clear) - this.actions = []; + this.clearActions(); if (this.sound !== params.sound) { this.sound = params.sound; @@ -478,7 +498,19 @@ export const Notification = GObject.registerClass({ // @label: the label for the action's button // @callback: the callback for the action addAction(label, callback) { - this.actions.push({label, callback}); + const action = new Action(label, callback); + this.actions.push(action); + this.emit('action-added', action); + } + + clearActions() { + if (this.actions.length === 0) + return; + + this.actions.forEach(action => { + this.emit('action-removed', action); + }); + this.actions = []; } setUrgency(urgency) { @@ -573,7 +605,7 @@ export const NotificationBanner = GObject.registerClass({ _addActions() { this.notification.actions.forEach(action => { - this.addAction(action.label, action.callback); + this.addAction(action.label, () => action.activate()); }); }